import Taro from "@tarojs/taro";

//身份证正则验证
const rsgIdNum = (value: string) => {
  if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value))) {
    throw Taro.showToast({
      title: '请输入正确的身份证号码',
      icon: 'none',
      duration: 2000
    })
  }
}

//社会信用代码
const rsgOrgNum = (value: string) => {
  if (!(/^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/
    .test(value))) {
    throw Taro.showToast({
      title: '请输入正确的社会信用代码',
      icon: 'none',
      duration: 2000
    })
  }
}

// 手机号验证
const phoneNum = (value: string) => {
  if (!(/^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/
    .test(value))) {
    throw Taro.showToast({
      title: '请输入正确的手机号码',
      icon: 'none',
      duration: 2000
    })
  }
}

// 四位纯数字验证
const rsgPwdNum = (value: string) => {
  if (!(/^\d{4}$/.test(value))) {
    throw Taro.showToast({
      title: '请输入四位数字',
      icon: 'none',
      duration: 2000
    })
  }
}

// 2~20个字符
const rsgName = (value: string) => {
  if (value.length <= 1 || value.length > 20) {
    throw Taro.showToast({
      title: '请输入2~20个字符',
      icon: 'none',
      duration: 2000
    })
  }
}

export {
  rsgIdNum,
  rsgOrgNum,
  phoneNum,
  rsgPwdNum,
  rsgName
}